﻿<UserControl x:Class="ICSharpCode.SharpDevelop.Refactoring.ContextActionsBulbControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Refactoring"
             xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"
             xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
	
	<UserControl.Resources>
		<!--<BitmapImage x:Key="BulbImage" UriSource="bulb.png" />-->
		<SolidColorBrush x:Key="OuterBorderBrush" Color="#436C82"></SolidColorBrush>
		<BitmapImage x:Key="PencilImage" UriSource="pencil.png" />
		<Geometry x:Key="DownArrowGeometry">M 0 0 L 2 3 L 4 0 Z</Geometry>
		<widgets:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" TrueValue="Visible" FalseValue="Hidden" />
		
		
		<!-- Expander -->
		<Style x:Key="ExpanderDownHeaderStyle"
		       TargetType="{x:Type ToggleButton}">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ToggleButton}">
						<Border Padding="{TemplateBinding Control.Padding}">
							<Grid>
								<Border Name="headerBorder" Height="8" >
									<Path Name="arrow" Data="M1,1.5L4.5,5 8,1.5" Stroke="#888" StrokeThickness="2"  HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="False" />
									<Border.Background>
										<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
											<GradientStop Color="White" Offset="0.5"></GradientStop>
											<GradientStop Color="#FFE9E9E9" Offset="1"></GradientStop>
										</LinearGradientBrush>
									</Border.Background>
								</Border>
							</Grid>
						</Border>
						
						<ControlTemplate.Triggers>
							<Trigger Property="IsChecked" Value="true">
								<Setter Property="Data"
								        Value="M 1,4.5  L 4.5,1  L 8,4.5"
								        TargetName="arrow"/>
							</Trigger>
							<Trigger Property="IsMouseOver"
							         Value="true">
								<Setter Property="Background"
								        TargetName="headerBorder">
									<Setter.Value>
										<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
											<GradientStop Color="White" Offset="0.2"></GradientStop>
											<GradientStop Color="#CCEBFF" Offset="1"></GradientStop>
										</LinearGradientBrush>
									</Setter.Value>
								</Setter>
								<Setter Property="Stroke"
								        Value="#304760"
								        TargetName="arrow"/>
							</Trigger>
							<Trigger Property="IsPressed"
							         Value="true">
							
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		<Style x:Key="{x:Type Expander}"
		       TargetType="{x:Type Expander}">
			<Setter Property="Foreground"
			        Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
			<Setter Property="Background"
			        Value="Transparent"/>
			<Setter Property="HorizontalContentAlignment"
			        Value="Stretch"/>
			<Setter Property="VerticalContentAlignment"
			        Value="Stretch"/>
			<Setter Property="BorderBrush"
			        Value="Transparent"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type Expander}">
						<DockPanel>
							<ToggleButton x:Name="HeaderSite"
							              DockPanel.Dock="Top"
							              Margin="0"
							              MinWidth="0"
							              MinHeight="0"
							              Style="{StaticResource ExpanderDownHeaderStyle}"
							              IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
							              Content="{TemplateBinding Header}"
							              ContentTemplate="{TemplateBinding HeaderTemplate}"
							              ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
							              Foreground="{TemplateBinding Foreground}"
							              Padding="{TemplateBinding Padding}"
							              FontFamily="{TemplateBinding FontFamily}"
							              FontSize="{TemplateBinding FontSize}"
							              FontStyle="{TemplateBinding FontStyle}"
							              FontStretch="{TemplateBinding FontStretch}"
							              FontWeight="{TemplateBinding FontWeight}"
							              HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
							              VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
							<ContentPresenter x:Name="ExpandSite"
								DockPanel.Dock="Bottom"
								Visibility="Collapsed"
								Focusable="false"
								HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
								VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
								Margin="{TemplateBinding Padding}"/>
						</DockPanel>
						<ControlTemplate.Triggers>
							<Trigger Property="IsExpanded"
							         Value="true">
								<Setter Property="Visibility"
								        Value="Visible"
								        TargetName="ExpandSite"/>
							</Trigger>
							<Trigger Property="IsEnabled"
							         Value="false">
								<Setter Property="Foreground"
								        Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		
		
		<!-- CheckBox -->
		<SolidColorBrush x:Key="CheckBoxFillNormal"
		                 Color="#F4F4F4"/>
		<SolidColorBrush x:Key="CheckBoxStroke"
		                 Color="#8E8F8F"/>
		<Style
			TargetType="{x:Type CheckBox}">
			<Setter Property="Foreground"
			        Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
			<Setter Property="Background"
			        Value="{StaticResource CheckBoxFillNormal}"/>
			<Setter Property="BorderBrush"
			        Value="{StaticResource CheckBoxStroke}"/>
			<Setter Property="BorderThickness"
			        Value="1"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type CheckBox}">
						<BulletDecorator Background="Transparent"
						                 SnapsToDevicePixels="true">
							<BulletDecorator.Bullet>
								<Border Background="Transparent" Padding="4 2">	<!-- To make the CheckBox easier to hit by mouse -->
									<aero:BulletChrome Background="Transparent"
										BorderBrush="Transparent"
										RenderMouseOver="false"
										RenderPressed="false"
										IsChecked="{TemplateBinding IsChecked}"/>
								</Border>
							
							
							</BulletDecorator.Bullet>
							<ContentPresenter Margin="{TemplateBinding Padding}"
								VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
								HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
								RecognizesAccessKey="True"
								SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
						</BulletDecorator>
						<ControlTemplate.Triggers>
							<Trigger Property="HasContent"
							         Value="true">
								
								<Setter Property="Padding"
								        Value="4,0,0,0"/>
							</Trigger>
							<Trigger Property="IsEnabled"
							         Value="false">
								<Setter Property="Foreground"
								        Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</UserControl.Resources>
	
	
	
	
	<!-- Visual tree -->
	
	<Grid Background="Transparent">
		<Grid.RowDefinitions>
			<RowDefinition></RowDefinition>
			<RowDefinition></RowDefinition>
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition></ColumnDefinition>
		</Grid.ColumnDefinitions>
		
		<!-- Header -->
		<Border x:Name="Header" Grid.Row="0" Grid.Column="0" Padding="2" BorderThickness="1" CornerRadius="2"
		        BorderBrush="#485763" HorizontalAlignment="Left" MouseUp="Header_MouseUp" ToolTipService.ShowDuration="3000">
			<Border.ToolTip>
				<ToolTip Placement="Top"><TextBlock>Available actions (Ctrl+T)</TextBlock></ToolTip>
			</Border.ToolTip>
			<Border.Background>
				<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
					<GradientStop Color="#F2F2F2" Offset="0"/>
					<GradientStop Color="#FFFFFF" Offset="0.2"/>
				</LinearGradientBrush>
			</Border.Background>
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>
				<Image Grid.Column="0" Width="12" Height="12" Stretch="Fill" Source="{StaticResource PencilImage}" />
				<!--				<Path Grid.Column="1" x:Name="Arrow" Fill="Black" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" Data="{StaticResource DownArrowGeometry}"/>-->
			</Grid>
			<!--<Border.Style>
				<Style TargetType="{x:Type Border}">
					<Style.Triggers>
						<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsOpen}" Value="True">
							<Setter Property="Background" Value="Red"></Setter>
						</DataTrigger>
					</Style.Triggers>
				</Style>
			</Border.Style>-->
		</Border>
		
		<!-- Content -->
		<Border x:Name="ContentBorder" Padding="0 0 8 8" Grid.Row="1" Grid.Column="0" MinWidth="200">
			<aero:SystemDropShadowChrome>
				<Border BorderThickness="1" Padding="0" Margin="0" Background="White" BorderBrush="{StaticResource OuterBorderBrush}">
					<StackPanel Orientation="Vertical">
						<local:ContextActionsControl x:Name="ActionsTreeView"
							DataContext="{Binding Actions}">
							<local:ContextActionsControl.ItemTemplate>
								<DataTemplate>
									<DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
										<Image Source="{Binding Image}" Margin="3 2 4 2" DockPanel.Dock="Left" />
										<!-- Command of every checkbox points to the command on the main DataContext (ContextActionsBulbViewModel) -->
										<CheckBox IsChecked="{Binding IsVisible}" VerticalAlignment="Center" DockPanel.Dock="Right"
										          Command="{Binding Path=DataContext.ActionVisibleChangedCommand,
										          RelativeSource={RelativeSource AncestorType={x:Type local:ContextActionsBulbControl}}}"
										          CommandParameter="{Binding}"
										          Visibility="{Binding DataContext.IsHiddenActionsExpanded,
										          RelativeSource={RelativeSource AncestorType={x:Type local:ContextActionsBulbControl}},
										          Converter={StaticResource BoolToVisibilityConverter}}"
										          Click="CheckBox_Click"
										          Focusable="False">
										</CheckBox>
										<TextBlock Text="{Binding Name}" Margin="0 2 20 2" />
									</DockPanel>
								</DataTemplate>
							</local:ContextActionsControl.ItemTemplate>
						</local:ContextActionsControl>
						<Expander x:Name="HiddenActionsExpander" Expanded="Expander_Expanded"
						          IsExpanded="{Binding IsHiddenActionsExpanded}"
						          Grid.Row="2" Grid.Column="0" Margin="0">
							<local:ContextActionsControl x:Name="HiddenActionsTreeView"
								DataContext="{Binding HiddenActions}">
								<local:ContextActionsControl.ItemTemplate>
									<DataTemplate>
										<DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
											<Image Source="{Binding Image}" Margin="3 2 4 2" DockPanel.Dock="Left" />
											<CheckBox IsChecked="{Binding IsVisible}" VerticalAlignment="Center" DockPanel.Dock="Right"
											          Command="{Binding Path=DataContext.ActionVisibleChangedCommand,
											          RelativeSource={RelativeSource AncestorType={x:Type local:ContextActionsBulbControl}}}"
											          CommandParameter="{Binding}"
											          Click="CheckBox_Click"
											          Focusable="False"></CheckBox>
											<TextBlock Text="{Binding Name}" Margin="0 2 20 2" />
										</DockPanel>
									</DataTemplate>
								</local:ContextActionsControl.ItemTemplate>
							</local:ContextActionsControl>
						</Expander>
					</StackPanel>
				</Border>
			</aero:SystemDropShadowChrome>
		</Border>
	</Grid>
</UserControl>